/**
 * losenote.com Inc.
 * Copyright (c) 2013-2013 All Rights Reserved.
 */
package com.losenote.model.ct;

import java.sql.Date;

import com.losenote.enums.DataStateEnum;
import com.losenote.model.CategoryItem;
import com.losenote.model.ContactDetail;
import com.losenote.model.FindNote;
import com.losenote.orm.FindNoteDO;

/**
 * 转换器
 * 
 * @author danjingyu
 * @version $Id: LostNoteConvertor.java, v 0.1 2013-10-26 下午4:58:54 danjingyu Exp $
 */
public class FindNoteConvertor {

    /**
     * 将领域对象转换成do
     * @param findNote
     * @return
     */
    public static FindNoteDO fromModel(FindNote findNote) {
        FindNoteDO findNoteDO = new FindNoteDO();
        //拷贝属性
        findNoteDO.setCategoryTypeId(findNote.getCategoryItem().getId());
        findNoteDO.setContactId(findNote.getContactDetail().getId());
        findNoteDO.setEffectiveDate(findNote.getFindDate());
        findNoteDO.setFindAddress(findNote.getFindAddress());
        findNoteDO.setTitle(findNote.getTitle());
        findNoteDO.setFindDate(findNote.getFindDate());
        findNoteDO.setPasswd(findNote.getPasswd());
        findNoteDO.setState(findNote.getState().getValue());
        findNoteDO.setGmtCreate(new java.util.Date());
        findNoteDO.setGmtModified(new java.util.Date());
        findNoteDO.setContent(findNote.getContent());
        findNoteDO.setCreator(findNote.getCreator());
        findNoteDO.setLastModifier(findNote.getLastModifier());
        return findNoteDO;
    }

    /**
     * 将领域对象转换成do
     * @param findNote
     * @return
     */
    public static FindNote fromDO(FindNoteDO findNoteDO, CategoryItem categoryItem,
                                  ContactDetail contactDetail) {
        FindNote findNote = new FindNote();
        findNote.setId(findNoteDO.getId());
        findNote.setCategoryItem(categoryItem);
        findNote.setContactDetail(contactDetail);
        findNote.setContent(findNoteDO.getContent());
        findNote.setEffectiveDate(new Date(findNoteDO.getEffectiveDate().getTime()));
        findNote.setFindAddress(findNoteDO.getFindAddress());
        findNote.setTitle(findNoteDO.getTitle());
        findNote.setFindDate(new Date(findNoteDO.getFindDate().getTime()));
        findNote.setPasswd(findNoteDO.getPasswd());
        findNote.setContent(findNoteDO.getContent());
        findNote.setState(DataStateEnum.getByValue(findNoteDO.getState()));
        findNote.setGmtCreate(findNoteDO.getGmtCreate());
        findNote.setGmtModified(findNoteDO.getGmtModified());
        findNote.setCreator(findNoteDO.getCreator());
        findNote.setLastModifier(findNoteDO.getLastModifier());
        return findNote;
    }
}
